package pandabay.service;

import java.util.*;

import pandabay.DAO.ProductDAO;
import pandabay.domain.Product;

public class SimpleProductManager implements ProductManager {

	private ProductDAO productDao;
	
    private List<Product> products;
    
    public List<Product> getProducts() {
        return products;
    }
    
    public void saveProduct(Product product) throws Exception {
    	productDao.saveProduct(product);
    }
    
    public Product searchProduct(String searchString) {
    	Product resultProduct = null;
    	for (Product product : products) {
    		if(searchString == product.getName()){
    			resultProduct = product;
    			break;
    		}
        }
        return resultProduct;
    }
    
    public Product getProduct(int id) {
    	Product resultProduct = null;
    	for (Product product : products) {
    		if(id == product.getId()){
    			resultProduct = product;
    			break;
    		}
        }
        return resultProduct;
    }

    public void setProducts(List<Product> products) {
        this.products = products;
    }
    
}